package edu.example;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Vector;



public class Review 
{
	private Reviewer reviewer;
	private Application app;
	
	private String EMailAddress;
	private String uploaddate;
	
	
	private String content;
	private double rating;
	private String lastModified;
	// the max length of the content
	private static final int MaxLength = 400;
	
	public Review(Reviewer initReviewer, Application initApp) {
		reviewer = initReviewer;
		app = initApp;
		content = "Unknown";
		rating = 0.0;
		setLastModified();
	}
	public Review(){
		
	}
	
	public void setReviewer(Reviewer initReviewer){
		reviewer = initReviewer;
	}

	// if the content length is not greater than the max length ,then set the content successfully
	public boolean setcontent(String initContent)
	{
		if (initContent.length()<=MaxLength){
			content = initContent;
			return true;
		}
		return false;
	}
	
	public void setRating(double initRating){
		rating = initRating;
	}
	
	public void setLastModified(){
		Calendar c = Calendar.getInstance();
		DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		lastModified = dateFormat.format(c.getTime());
	}
	
	public void setLastModified(String date){
		Calendar c = Calendar.getInstance();
		DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		String start = date;
		int year = Integer.parseInt(start.substring(0, 4));
		int month = Integer.parseInt(start.substring(5, 7));
		int day = Integer.parseInt(start.substring(8, 10));
		int hour = Integer.parseInt(start.substring(11, 13));
		int min = Integer.parseInt(start.substring(14, 16));
		int sec = Integer.parseInt(start.substring(17));
		System.out.println("Separate into pieces: "+year+"+"+month+"+"+day+"+"+hour+"+"+min+"+"+sec);
		c.set(year, month-1, day, hour, min, sec);
		lastModified = format.format(c.getTime());
		System.out.println("After converting: "+format.format(c.getTime()));
		
	}
	//Accessors
	//public String getEMailAddress()  		     {return EMailAddress;}
	public Reviewer getReviewer() {return reviewer;}
	public String getcontent() {return content;}
	public double getRating() {return rating;}
	public String getLastModified() {return lastModified;}
	public Application getApplication()	{return app;}
}
